package com.example.web;

import com.example.vo.Result;
import com.example.service.UserService;
import com.example.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.security.Principal;

@RestController
@RequestMapping("user")
@Api(value = "User Controller", consumes = "用户接口")
public class UserController extends BaseController {

    @Autowired
    UserService userService;

    @GetMapping("/get")
    public Mono<Result> getUser(Principal principal) {
        return resultMono(Result.success("查询成功！", principal));
    }

    @GetMapping(value = "/queryList")
    @ApiOperation(value = "Query user list", response = Result.class)
    public Mono<Result> queryList(UserVo userVo) {
        return userService.findAll(userVo)
                .collectList()
                .map(pageResults -> Result.success("查询成功！", pageResults));
    }
}
